package com.ruoyi.web.controller.credit;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.ContractIncomeCustomers;
import com.ruoyi.credit.service.IContractIncomeCustomersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收入类合同合约方关系Controller
 *
 * @author zhulei
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/contractCustomers")
public class ContractIncomeCustomersController extends BaseController
{
    private String prefix = "credit/contractCustomers";

    @Autowired
    private IContractIncomeCustomersService contractIncomeCustomersService;

    @RequiresPermissions("credit:contractCustomers:view")
    @GetMapping()
    public String contractCustomers()
    {
        return prefix + "/contractCustomers";
    }

    /**
     * 查询收入类合同合约方关系列表
     */
    @RequiresPermissions("credit:contractCustomers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractIncomeCustomers contractIncomeCustomers)
    {
        startPage();
        List<ContractIncomeCustomers> list = contractIncomeCustomersService.selectContractIncomeCustomersList(contractIncomeCustomers);
        return getDataTable(list);
    }

    /**
     * 导出收入类合同合约方关系列表
     */
    @RequiresPermissions("credit:contractCustomers:export")
    @Log(title = "收入类合同合约方关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContractIncomeCustomers contractIncomeCustomers)
    {
        List<ContractIncomeCustomers> list = contractIncomeCustomersService.selectContractIncomeCustomersList(contractIncomeCustomers);
        ExcelUtil<ContractIncomeCustomers> util = new ExcelUtil<ContractIncomeCustomers>(ContractIncomeCustomers.class);
        return util.exportExcel(list, "收入类合同合约方关系数据");
    }

    /**
     * 新增收入类合同合约方关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存收入类合同合约方关系
     */
    @RequiresPermissions("credit:contractCustomers:add")
    @Log(title = "收入类合同合约方关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractIncomeCustomers contractIncomeCustomers)
    {
        return toAjax(contractIncomeCustomersService.insertContractIncomeCustomers(contractIncomeCustomers));
    }

    /**
     * 修改收入类合同合约方关系
     */
    @RequiresPermissions("credit:contractCustomers:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ContractIncomeCustomers contractIncomeCustomers = contractIncomeCustomersService.selectContractIncomeCustomersById(id);
        mmap.put("contractIncomeCustomers", contractIncomeCustomers);
        return prefix + "/edit";
    }

    /**
     * 修改保存收入类合同合约方关系
     */
    @RequiresPermissions("credit:contractCustomers:edit")
    @Log(title = "收入类合同合约方关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractIncomeCustomers contractIncomeCustomers)
    {
        return toAjax(contractIncomeCustomersService.updateContractIncomeCustomers(contractIncomeCustomers));
    }

    /**
     * 删除收入类合同合约方关系
     */
    @RequiresPermissions("credit:contractCustomers:remove")
    @Log(title = "收入类合同合约方关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractIncomeCustomersService.deleteContractIncomeCustomersByIds(ids));
    }
}
